#!/usr/bin/env python

import os, sys, json


def main(argv):
    output_prefix = "output/"
    if not os.path.exists(output_prefix):
        os.system("mkdir "+output_prefix)

    output_task_usage = "output_task_usage/"
    output_job_events = "output_job_events/"
    users = os.listdir(output_job_events)

    for user in users:
        user_folder = output_prefix + user + "/"
        os.system("mkdir "+user_folder)

        for single_class in os.listdir(output_job_events+user):
            original_class_file = output_job_events+user+"/"+single_class
            with open(original_class_file, "r") as f:
                job_events = json.load(f)

            os.system("mkdir "+user_folder+single_class)
            for job in job_events:
                if os.path.exists(output_task_usage+job):
                    mv_command = "mv "+output_task_usage+job+" "+user_folder+single_class
                    os.system(mv_command)


if __name__ == "__main__":
    main(sys.argv)